package gwtappcontainer.server;

import static com.googlecode.objectify.ObjectifyService.ofy;
import gwtappcontainer.client.StatsService;
import gwtappcontainer.shared.ViewProp;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.googlecode.objectify.ObjectifyService;

@SuppressWarnings("serial")
public class StatsServiceImpl extends RemoteServiceServlet implements
    StatsService { 
	
	static {
		ObjectifyService.factory().register(ViewStatsEntity.class);			
	}
	
	public StatsServiceImpl() {		
	}

	@Override
	public void recordView(ViewProp viewProp) {
		
		ViewStatsEntity toSave = new ViewStatsEntity(viewProp);
		toSave.ip = getThreadLocalRequest().getRemoteAddr();
		
		ofy().save().entity(toSave); //can be async, so no need for now()	
	}
}